<template>
  <div class="pay">
    <div class="pay-container">
      <div class="pay-header">
        <div class="pay-log-img">
          <img src="./images/Vmall_red.png" alt="log" />
          <span>收银台</span>
        </div>
      </div>
      <div class="pay-two">
        <div class="pay-two-left">
          <img src="./images/success_icon.png" alt="" />
        </div>
        <div class="pay-two-right">
          <div class="pay-two-top">
            <div class="pay-two-top-left">
              <div class="pay-a">
                <h4>订单提交成功，只差付款了~</h4>
                <div class="pay-b">
                  <span class="pay-font">订单号：</span>
                  <span>{{ payList.orderId }}</span>
                </div>
              </div>
            </div>
            <div class="pay-two-top-right">
              <span>订单金额:</span>
              <span class="money-pay">￥{{ payList.totalFee }}</span>
            </div>
          </div>
          <div class="pay-two-bottom">
            <div class="span-a">
              请您在
              <span>{{ time }}</span>
              <!--  <span>23小时 47分43秒</span> -->
              内完成支付，否则订单将自动取消。
            </div>
            <nav><a href="#">订单详情 v</a></nav>
          </div>
        </div>
      </div>
      <el-tabs type="border-card" class="pay-tabs">
        <el-tab-pane label="常用">
          <div class="pay-tabs-1">
            <div class="pay-tabs-1-pro">推荐</div>
            <div class="pay-tabs-1-pro1">推荐</div>
            <ul>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/ALIPAY.png?v=20220319"
                  alt="支付宝"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/WXPAY.png?v=20220319"
                  alt="微信"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/HUABEI.png?v=20220319"
                  alt="花呗"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/HUAWEIPAY.png?v=20220319"
                  alt="银联"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/CMBLIFE.png?v=20220319"
                  alt="银联"
                />
              </li>
            </ul>
          </div>
        </el-tab-pane>
        <el-tab-pane label="平台支付">
          <div class="pay-tabs-1">
            <div class="pay-tabs-1-pro">推荐</div>
            <div class="pay-tabs-1-pro1">推荐</div>
            <ul>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/ALIPAY.png?v=20220319"
                  alt="支付宝"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/WXPAY.png?v=20220319"
                  alt="微信"
                />
              </li>
            </ul>
          </div>
        </el-tab-pane>
        <el-tab-pane label="分期支付">
          <div class="pay-tabs-1">
            <div class="pay-tabs-1-pro">推荐</div>
            <div class="pay-tabs-1-pro1">推荐</div>
            <ul>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/WXPAY.png?v=20220319"
                  alt="微信"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/HUABEI.png?v=20220319"
                  alt="花呗"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/HUAWEIPAY.png?v=20220319"
                  alt="银联"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/CMBLIFE.png?v=20220319"
                  alt="银联"
                />
              </li>
            </ul>
          </div>
        </el-tab-pane>
        <el-tab-pane label="网云支付">
          <div class="pay-tabs-1">
            <div class="pay-tabs-1-pro">推荐</div>
            <div class="pay-tabs-1-pro1">推荐</div>
            <ul>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/ALIPAY.png?v=20220319"
                  alt="支付宝"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/WXPAY.png?v=20220319"
                  alt="微信"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/HUABEI.png?v=20220319"
                  alt="花呗"
                />
              </li>
              <li>
                <img
                  src="https://res.vmallres.com/ips/pc/20220319/images/serverIcon/2x/HUAWEIPAY.png?v=20220319"
                  alt="银联"
                />
              </li>
            </ul>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div class="btn">
        <el-button type="danger" @click="showDialogPay">确认支付</el-button>
      </div>
    </div>
    <el-dialog title="微信支付" :visible.sync="dialogVisible" width="30%">
      <div class="imgCode">
        <img :src="codeUrl" alt="" />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">支付遇到问题</el-button>
        <el-button type="primary" @click="$router.push('/paysuccess')"
          >已完成支付</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import QRCode from "qrcode";
import { reqGetPayApi, reqPayStatusApi } from "@/api/payApi";
export default {
  name: "Xpay",
  data() {
    return {
      dialogVisible: false,
      payList: {},
      codeUrl: "",
      time: "",
    };
  },
  async mounted() {
    this.reqGetPay();
    this.countDown();
  },
  methods: {
    async reqGetPay() {
      const orderId = this.$route.query.orderId;
      this.payList = await reqGetPayApi(orderId);
    },

    async showDialogPay() {
      this.dialogVisible = true;
      const orderId = this.$route.query.orderId;
      this.codeUrl = await QRCode.toDataURL(this.payList.codeUrl);
      // 定时器加请求 = axios轮询
      this.timeId = setInterval(async () => {
        await reqPayStatusApi(orderId);
        this.$router.push("/paysuccess");
        clearInterval(this.timeId);
      }, 7000);
    },

    countDown() {
      let calculator = 1 * 24 * 60 * 60;
      this.timer = setInterval(() => {
        calculator--;
        if (calculator <= 0) {
          clearInterval(this.timer);
          return;
        }
        let h = parseInt((calculator / 60 / 60) % 24);
        let m = parseInt((calculator / 60) % 60);
        let s = parseInt(calculator % 60);
        this.time = h + "小时" + m + "分钟" + s + "秒";
      }, 1000);
    },
  },

  beforeDestroy() {
    clearInterval(this.timeId);
    clearInterval(this.timer);
  },
};
</script>

<style lang="less" scoped>
.pay {
  background-color: #fff;
  .pay-container {
    margin: 0 auto;
    width: 1200px;
    .pay-log-img {
      margin-top: 40px;
      padding-bottom: 20px;
      border-bottom: 2px solid #63aa56;
      img {
        width: 134px;
        height: 60px;
        vertical-align: middle;
      }
      span {
        display: inline-block;
        line-height: 20px;
        margin-left: 26px;
        padding: 0 26px;
        border-left: 1px solid #cccccc;
        color: #3a3a3a;
        letter-spacing: 1px;
        font-size: 16px;
      }
    }
    .pay-two {
      overflow: hidden;
      .pay-two-left {
        float: left;
        width: 60px;
        height: 60px;
        margin: 30px 21px 0 34px;
      }
      .pay-two-right {
        float: left;
        width: 1063px;
        padding: 28px 22px 20px 0;
        .pay-two-top {
          margin-bottom: 20px;
          overflow: hidden;
          .pay-two-top-left {
            float: left;
            .pay-a {
              display: flex;
              h4 {
                font-size: 18px;
                color: #63aa56;
              }
              .pay-b {
                line-height: 24px;
                color: #da3232;
                margin-left: 15px;
                font-size: 12px;
              }
              .pay-font {
                color: #3a3a3a;
                font-weight: bolder;
              }
            }
          }
          .pay-two-top-right {
            float: right;
            font-size: 12px;
            .money-pay {
              font-size: 24px;
              color: #da3232;
              margin-right: 6px;
              font-weight: 600;
            }
          }
        }
        .pay-two-bottom {
          overflow: hidden;
          .span-a {
            float: left;
            span {
              color: red;
            }
          }
          nav {
            float: right;
            a {
              font-size: 12px;
            }
          }
        }
      }
    }
    .pay-tabs {
      margin-top: 20px;
      .pay-tabs-1 {
        position: relative;
        ul {
          display: flex;
          flex-wrap: wrap;
          justify-content: flex-start;
          li {
            margin: 20px 8px;
            width: 256px;
            height: 52px;
            line-height: 52px;
            text-align: center;
            border: 1px solid #cccccc;
            cursor: pointer;
            img {
              width: auto;
              display: inline-block;
              height: 30px;
            }
          }
        }
        .pay-tabs-1-pro,
        .pay-tabs-1-pro1 {
          width: 40px;
          height: 20px;
          font-size: 12px;
          color: #fff;
          position: absolute;
          text-align: center;
          background-color: red;
        }
        .pay-tabs-1-pro {
          top: 0px;
          left: 282px;
        }
        .pay-tabs-1-pro1 {
          top: 0px;
          left: 8px;
        }
      }
    }
    .btn {
      margin: 20px 0;
      display: flex;
      justify-content: end;
    }
  }
}
.imgCode {
  display: flex;
  justify-content: center;
}
</style>